package org.aileen.java_chatroom.api;

import jakarta.annotation.Resource;
import org.aileen.java_chatroom.model.Message;
import org.aileen.java_chatroom.model.MessageMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageAPI {
    @Resource
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public Object getMessage(int sessionId){
        List<Message> messages =  messageMapper.getMessagesBySessionId(sessionId);
        // 针对查询结果 , 进行逆置操作,毕竟界面上得到的应该是按照时间升序排序的结果,我们通过水库Mapper查询到的是降序排序的消息
        Collections.reverse(messages);
        return messages;
    }
}
